using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PACKETPARSERMAX20.CORE;


namespace PACKETPARSERMAX20.CORE.DEFINITIONS
{
    public class SMSG_COMPRESSED_MOVES_DEF : DefinitionBase
    {


        public override bool Process()
        {
            ResetPosition();
            //InitLog();

            if (OpcodeEnum == Opcodes.SMSG_COMPRESSED_MOVES)
            {
                base.Stream.Position = 0;

                int i = 0;

                

                while (AvailableBytes > 0)
                {
                    i++;

                    byte size = ReadByte();
                    long last_position = base.Stream.Position;
                    base.Stream.Position = last_position;

                    UInt16 op = ReadUInt16();
                    DefinitionBase tDEF = base.GetDefinition(op);
                    tDEF.Process(Opcode, op, last_position + 2, size - 2);
                    ////if (LogIt) tDEF.Log();
                    ////if (LogIt) LogAppendLine(tDEF.OpcodeName);

                    long read_size = tDEF.Reader.BaseStream.Position - last_position;

                    if (read_size < size)
                    {
                        long left_over_size = size - read_size;
                        base.Stream.Position = left_over_size + tDEF.Reader.BaseStream.Position;
                        //byte[] bytes = ReadBytes((int)left_over_size);
                    }
                    else
                    {
                        base.Stream.Position = tDEF.Reader.BaseStream.Position;
                    }
                }
            }
            ////Core.Update();
            return Validate();


        }


    }
}
